package part19;

import java.util.Random;

/**
 * @author wcj
 * @Date 2021/6/5 17:36
 * @Version 1.0
 */
public class Part196 {
    private static Random random = new Random(47);

    public static <T extends Enum<T>> T random(Class<T> type) {
        return random(type.getEnumConstants());
    }

    public static <T> T random(T[] values) {
        return values[random.nextInt(values.length)];
    }

    /**
     * 随即返回enum中实例的工具类
     *
     * @param args
     */
    public static void main(String[] args) {
        for (int i = 0; i < 20; i++) {
            System.out.println(random(Activity.class));
        }
    }
}

enum Activity {
    RUNNING,
    DODGING,
    JUMPING,
    FALLING,
    FLYING,
}
